jquery教程

推荐列表 站点导航

当前位置:首页 > jquery > jquery教程 >

js 隔行变色与鼠标悬停自动变色的实现代码

来源:网络整理  作者:fen  发布时间:2020-12-25 12:12
如何用js实现隔行变色,以及当鼠标移动到某块区域时自动变色的功能?本文分享一段实现此功能的js代码,希望对大...

一段js效果,实现隔行变色与鼠标移动到某区域时自动变色。
代码 如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>隔行变色--</title> <style> .top{ background-color:#F00; color:#006; } table{ border:1px #C06 dashed; border-collapse:collapse; } th,td{ border:#999 1px solid; } .one{ background-color:#ffc; } .two{ background-color:#fcc; } .over{ background-color:#666; } </style> <script language="javascript" type="application/javascript"> function geHang(){ //获取所有的tr var trlist=document.getElementsByTagName("tr"); for(var i=1;i<trlist.length;i++){ //进行遍历,并且判断 if(i%2==0){ trlist[i].className="two"; }else{ trlist[i].className="one"; } var oldcolor; //实现当鼠标移动到该行,该行背景加深、 trlist[i].onmouseover=function(){ oldcolor=this.className; //onmouseover会传匿名函数 this--将鼠标移上去会获取当前值 //重新设置新颜色 this.className="over"; } trlist[i].onmouseout=function(){ //当鼠标离开,自动还原颜色 this.className=oldcolor; } } } /IT之家 //当鼠标移动上来时候,改变当前颜色 function over(trNode){ //把原来的颜色,另存一下 color=trNode.className; //将当前行的颜色设over定为 trNode.className="over"; } //当鼠标移动开时候,把原来的行的颜色设定回来 function out(trNode){ //还原以前的颜色 trNode.className=color; }IT之家/ </script> </head> <body onload="geHang()"> <table> <tr class="top"> <th>姓名</th> <th>年龄</th> <th>籍贯</th> <th>电话</th> <th>邮编</th> </tr> <tr onmouseover="over(this)" onmouseout="out(this)"> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr onmouseover="over(this)" onmouseout="out(this)"> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr onmouseover="over(this)" onmouseout="out(this)"> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr onmouseover="over(this)" onmouseout="out(this)"> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr onmouseover="over(this)" onmouseout="out(this)"> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> </table> </body> </html>

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jq/jc/8888.shtml

最新文章
PHP识别相片是否是颠倒的 PHP识别相片是否是颠倒的

时间:2020-12-28

python编程有哪些ide python编程有哪些ide

时间:2020-12-28

python开发工程师是做什么 python开发工程师是做什么

时间:2020-12-28

php构造函数的作用 php构造函数的作用

时间:2020-12-28

php怎么跟数据库连接 php怎么跟数据库连接

时间:2020-12-28

php实现顺序线性表 php实现顺序线性表

时间:2020-12-28

Python多重继承中的菱形继 Python多重继承中的菱形继

时间:2020-12-28

php中break的作用 php中break的作用

时间:2020-12-28

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

js 隔行变色与鼠标悬停自动变色的实现代码

2020-12-25 编辑:fen

一段js效果,实现隔行变色与鼠标移动到某区域时自动变色。
代码 如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>隔行变色--</title> <style> .top{ background-color:#F00; color:#006; } table{ border:1px #C06 dashed; border-collapse:collapse; } th,td{ border:#999 1px solid; } .one{ background-color:#ffc; } .two{ background-color:#fcc; } .over{ background-color:#666; } </style> <script language="javascript" type="application/javascript"> function geHang(){ //获取所有的tr var trlist=document.getElementsByTagName("tr"); for(var i=1;i<trlist.length;i++){ //进行遍历,并且判断 if(i%2==0){ trlist[i].className="two"; }else{ trlist[i].className="one"; } var oldcolor; //实现当鼠标移动到该行,该行背景加深、 trlist[i].onmouseover=function(){ oldcolor=this.className; //onmouseover会传匿名函数 this--将鼠标移上去会获取当前值 //重新设置新颜色 this.className="over"; } trlist[i].onmouseout=function(){ //当鼠标离开,自动还原颜色 this.className=oldcolor; } } } /IT之家 //当鼠标移动上来时候,改变当前颜色 function over(trNode){ //把原来的颜色,另存一下 color=trNode.className; //将当前行的颜色设over定为 trNode.className="over"; } //当鼠标移动开时候,把原来的行的颜色设定回来 function out(trNode){ //还原以前的颜色 trNode.className=color; }IT之家/ </script> </head> <body onload="geHang()"> <table> <tr class="top"> <th>姓名</th> <th>年龄</th> <th>籍贯</th> <th>电话</th> <th>邮编</th> </tr> <tr onmouseover="over(this)" onmouseout="out(this)"> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr onmouseover="over(this)" onmouseout="out(this)"> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr onmouseover="over(this)" onmouseout="out(this)"> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr onmouseover="over(this)" onmouseout="out(this)"> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr onmouseover="over(this)" onmouseout="out(this)"> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> </table> </body> </html>

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jq/jc/8888.shtml

相关文章

风云图片

推荐阅读

返回jquery教程频道首页